package me.keiwu.user.service;

import me.keiwu.pub.data.ResponseV2;
import me.keiwu.pub.data.service.OtherUserInfoBean;
import me.keiwu.pub.data.service.UserInfoBean;
import me.keiwu.pub.data.wx.WXUserInfoData;
import me.keiwu.user.domain.User;
import me.keiwu.user.domain.UserForm;
import me.keiwu.pub.data.Response;
import me.keiwu.pub.data.wx.WXSessionData;
import me.keiwu.user.domain.UserStep;
import me.keiwu.user.domain.UserTotalStep;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * Created by kei on 06/11/2017.
 */
public interface UserService {

	/**
	 * 小程序登录，返回access_token和其他信息
	 * 
	 * @param data
	 * @param session
	 * @param channel
	 * @return
	 */
	Response login(WXUserInfoData data, WXSessionData session, String channel);

	/**
	 * 保存用户，刷新缓存
	 * 
	 * @param user
	 * @return
	 */
	User save(User user);

	/**
	 * 批量保存用户，刷新缓存
	 * 
	 * @param users
	 */
	void save(Iterable<User> users);

	/**
	 * 通过id获取user
	 * 
	 * @param userId
	 * @return
	 */
	User getUserById(Long userId);

	/**
	 * 通过id列表获取用户列表
	 * 
	 * @param idList
	 * @return
	 */
	List<User> getUsersByIdList(List<Long> idList);

	/**
	 * 通过id获取userInfo（传输bean）,不刷新刷新缓存
	 * 
	 * @param userId
	 * @return
	 */
	UserInfoBean getUserInfo(Long userId);

	/**
	 * 从缓存中读取userInfo,读不到调用getUserInfo，并刷新缓存
	 * 
	 * @param userId
	 * @return
	 */
	UserInfoBean getUserInfoCache(Long userId);


	/**
	 * 通过openId获取userInfo（传输bean）,不刷新刷新缓存
	 * @param openId
	 * @return
	 */
	UserInfoBean getUserInfoByOpenId(String openId);

	/**
	 * 获取用户虚拟形象
	 * 
	 * @param userId
	 * @return
	 */
	String getUserAvatar(Long userId);

	/**
	 * 通过id获取其他人的userInfo（传输bean）
	 * 
	 * @param userId
	 * @return
	 */
	OtherUserInfoBean getOtherUserInfo(Long userId);

	Page<User> getDailyLoginUser(String nickName, int page, int size);

	Page<User> getAllLoginUser(String nickName, int page, int size);

	Page<User> findWithoutUsers(List<Long> withoutList, String nickName, Integer page, Integer size);

	/**
	 * 变更星币，可正可负
	 * 
	 * @param user
	 * @param gold
	 * @return
	 */
	boolean changeGold(User user, int gold);

	boolean changeGold(long userId, int gold);

	boolean updateGold(long userId, int newGold);

	boolean updateGold(User user, int newGold);

	UserStep getDailyUserStep(Long userId);

	List<UserStep> getUserSteps(Long userId, Integer fromDays, Integer toDays);

	UserTotalStep getUserTotalStep(Long userId);

	void cleanUserCache(Long userId);

	ResponseV2 getRank(Long start, Long end);

	ResponseV2 getUserRank(Long userId);

	ResponseV2 joinGroupRank(String openGId, Long userId, String groupName);

	ResponseV2 getGroupRank(String openGId, Long start, Long end);

	ResponseV2 getUserGroupRank(String openGId, Long userId);

	ResponseV2 getUserGroupList(Long userId, Integer page, Integer size);

	ResponseV2 shareGetGold(Long userId);

	ResponseV2 saveUserForm(UserForm userForm);

	UserForm getOldestUserFormById(Long userId);

	// boolean deleteUserForm(String formId);

	boolean deleteExpiredForm();

	boolean updateUsedForm(String formId);

	boolean deleteUsedForm(Long id);

	Page<User> getInactiveUser(Integer page, Integer size);

	ResponseV2 getRankForAdmin(Long start, Long end);

}
